package torchtools.io;

import java.awt.Graphics;

/**
 * Describes a Torchlight icon attached to an Imageset file.
 * 
 * @author Matt
 */
public class TLIcon {
    public final TLImageSet Set;

    public final String Name;
    public final int XPos;
    public final int YPos;
    public final int Width;
    public final int Height;

    public TLIcon(TLImageSet Set, String Name, int XPos, int YPos,
                    int Width, int Height) {
        this.Set = Set;
        this.Name = Name;
        this.XPos = XPos;
        this.YPos = YPos;
        this.Width = Width;
        this.Height = Height;
    }

    public void draw(Graphics g, int x, int y) {
        draw(g, x, y, -1, -1);
    }

    /** Paints the specified image to an area on the canvas. */
    public void draw(Graphics g, int x, int y, int width, int height) {
        //if width/height is not specified, default to image size
        int dW = width!=-1 ? width : Width;
        int dH = height!=-1 ? height : Height;

        int dx1 = x;
        int dy1 = y;
        int dx2 = dx1+dW;
        int dy2 = dy1+dH;
        int sx1 = XPos;
        int sy1 = YPos;
        int sx2 = sx1 + Width;
        int sy2 = sy1 + Height;
        g.drawImage(Set.Sheet, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null, null);
    }
}